home *** CD-ROM | disk | FTP | other *** search
- alindbac@sw.seisy.abb.se (Anders Lindback) writes:
-
- >> Why is it not allowed to delegate the initialisation to another
- >> constructor
- >>
- >> class X
- >> {
- >> public:
- >> X (int i) : i_(i) {}
- >>
- >> X () : X(34) {} // Not allowed
-
- > Well, one could use a similar thing using a member function:
-
- > X (int i) { init(i); }
- > X () { init(34); }
-
- > where init is a member function for class X.
-
- The problem is that member functions can't initialize anything. Often
- this is just a minor nuisance: the X ctor calls the default ctor of
- the data member, which gets then immediately overwritten by assignment
- in init(). But you can't use this technique when you deal with const
- and reference members. Thus the syntax "X () : X(34) {}" would still
- be useful. Has anyone written a proposal?
- [ To submit articles: Try just posting with your newsreader.
- If that fails, use mailto:std-c++@ncar.ucar.edu
- FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
- Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
- Comments? mailto:std-c++-request@ncar.ucar.edu
- ]
-